#include<bits/stdc++.h>

using namespace std;

const int int_max = 0x7fffffff;

int findMinofTrip(int A[], int n, int B[], int m, int C[], int p) {
    int i = 0, j = 0, k = 0, D_min = int_max;
    // D_min如果等于0，那么肯定是最终结果，可以直接结束循环
    while (i < n && j < m && k < p && D_min > 0) {
        int D = abs(A[i] - B[j]) + abs(B[j] - C[k]) + abs(C[k] - A[i]);
        if (D < D_min)
            D_min = D;
        if (A[i] == min(min(A[i], B[j]), C[k]))
            i++;
        else if (B[j] == min(min(A[i], B[j]), C[k]))
            j++;
        else
            k++;
    }
    return D_min;
}

int main() {
    //  测试
    int n = 3;
    int S_1[] = {-1, 0, 9};
    int m = 4;
    int S_2[] = {-25, -10, 10, 11};
    int p = 4;
    int S_3[] = {2, 9, 17, 30, 41};
    cout << findMinofTrip(S_1, n, S_2, m, S_3, p) << endl;
    return 0;
}